// Copyright 2009 Google Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#ifndef POPDIAG_CONFIG_THUNDERBIRD_H__
#define POPDIAG_CONFIG_THUNDERBIRD_H__

#include <QtCore/QDir>
#include <QtCore/QTextStream>

#include "config/configverifier.h"

namespace popdiag {

class IniFileReader;
class PrefsJsReader;

class Thunderbird : public ConfigVerifier {
  Q_OBJECT;
 public:
  Thunderbird();
  virtual ~Thunderbird();

  virtual QString program_name() const;
  virtual bool CheckConfiguration(VerificationSet *out) const;
 private:

  // get the directory under which mozilla thunderbird settings will be found.
  // this is platform dependent.  Returns true iff we found the directory
  bool GetDataDirectory(QDir *out) const;
  // Return candidates for the directory, with the preferred candidate first.
  // If the user has multiple versions installed, we want to present only the
  // most recent one to him, as it might otherwise be confusing.
  QStringList GetDataDirectoryLocations() const;
  IniFileReader *ReadProfilesIni(QDir *profile_base_dir) const;
  PrefsJsReader *ReadPrefsJs(const QString &prefs_js_path) const;

  // find all the interesting profiles and fill in the faults for them:
  void ReadProfile(const QString &name, const QString &js_prefs_path,
                   VerificationSet *results) const;

  // having found an interesting profile, fill in the faults for it:
  void CheckProfile(const PrefsJsReader &jsprefs, const QString &server_prefix,
                    const QString &account_prefix, const QString &email_target,
                    FaultSet *faults) const;
};

class ThunderbirdInspection : public VerificationResult {
  Q_OBJECT;
 public:
  ThunderbirdInspection(const QString &profile_name,
                        const QString &prefs_js_path,
                        const QString &server_prefix,
                        const QString &account_prefix,
                        enum ServerType server_type);

  virtual void Recalculate(const QString &email_address);
 private:
  void CheckProfile(const PrefsJsReader &prefsjs);

  const QString profile_name_;
  const QString prefs_js_path_;
  const QString server_prefix_;
  const QString account_prefix_;
};

}  // namespace popdiag

#endif  // POPDIAG_CONFIG_THUNDERBIRD_H__
